/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.losenote.base.LnConstrant;
import com.losenote.base.template.AbstractServiceImpl;
import com.losenote.base.template.BlankCallback;
import com.losenote.core.MessageComponent;
import com.losenote.model.OperateContext;
import com.losenote.orm.MessageDO;
import com.losenote.service.MessageService;
import com.losenote.service.result.LnResult;

/**
 * 消息发送实现类
 * 
 * @author danjingyu
 * @version $Id: MessageServiceImpl.java, v 0.1 2013-12-1 下午4:37:56 danjingyu Exp $
 */
public class MessageServiceImpl extends AbstractServiceImpl implements MessageService {

    /**消息组件*/
    @Autowired
    private MessageComponent messageComponent;

    /** 
     * @see com.losenote.service.MessageService#saveMessage(com.losenote.model.Message, com.losenote.model.OperateContext)
     */
    public LnResult saveMessage(final MessageDO messageDO, final OperateContext operatorContext) {
        return serviceTemplate.execute(LnResult.class, new BlankCallback() {

            public LnResult executeService() {
                //【1】发布文章
                int id = messageComponent.saveMessage(messageDO, operatorContext);

                //【2】记录操作日志
                LnResult result = LnResult.retSuccess();
                result.getRelatedAttr().put(LnConstrant.ID, id);

                //【3】返回日志
                return result;
            }

        });
    }

    public void setMessageComponent(MessageComponent messageComponent) {
        this.messageComponent = messageComponent;
    }

}
